package com.entity;

import java.util.Scanner;

public class text {
    public static void main(String[] args) {
        System.out.println("计算1-n的和：" + sum(6));

    }
    public static int sum ( int n){
        int total = 0;//定义变量total表示1-n的和
        for (int i = 1; i <= n; i++) {
            total += i;
        }
        return total;
    }
}
